import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from "axios";
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI);

// 配置路径
axios.defaults.baseURL = 'http://localhost:9998'


Vue.config.productionTip = false

// 添加拦截器
axios.interceptors.response.use(function (response) {
  return response.data;
}, function (error) {
  // 对响应错误做点什么
  return Promise.reject(error);
});


// 配置axios的请求拦截,设置请求头,设置token
axios.interceptors.request.use(config => {
  if (store.state.token) {
    // 在发送请求之前给每个请求头设置token
    config.headers['Authorization'] = store.state.token
  }
  return config;
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error);
});


new Vue({
  router,
  store,
  render: function (h) { return h(App) }
}).$mount('#app')
